package no.uio.inf5750.j2mewsclient;

import java.io.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import org.xml.sax.helpers.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
//import javax.microedition.io.file.*;
import javax.microedition.lcdui.*;
import no.uio.inf5750.j2mewsclient.*;

public class SimpleMIDlet extends MIDlet
{
  public SimpleMIDlet() {
  }
	
	String msg;
//	MyEventHandler myEventHandler = new MyEventHandler();
	
  protected void startApp()
  {
    try
  
    {
      SAXParserFactory factory = SAXParserFactory.newInstance();
      SAXParser saxParser = factory.newSAXParser();

// Initialize the URI and XML Document InputStream
//String uri = "http://localhost:8080/dhis-web-webservice/getAllDataSets.service";

String uri = "http://208.76.222.114/dhis-webservice/getAllDataSets.service";

      HttpConnection hc = (HttpConnection)Connector.open(uri);
  //    InputStream is = hc.openInputStream();
//InputStream inputStream = getXMLDoc(uri);
InputStream inputStream = hc.openInputStream();
// Create an InputSource from the InputStream
InputSource inputSource = new InputSource(inputStream);

// Parse the input XML document stream, using my event handler
//  MyEventHandler myEventHandler = new MyEventHandler();
saxParser.parse(inputSource, new MyEventHandler(this));
    }
    catch(Exception ex) {
	System.out.println("Problem parsing...please check your connection");
	msg = "Please check your webservice connection";
	}
}

  protected void alert(String msg)
  {
    Display display = Display.getDisplay(this);
    Form form = new Form("Welcome to the DHIS!");
//	msg = myEventHandler.msg;
    form.append(msg);
    display.setCurrent(form);
	
  }

  protected void pauseApp() {}
  protected void destroyApp(boolean bool) {}
}
